<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0040)http://timyang.net/java/java_gc_tunning/ -->
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Java垃圾回收调优 – Tim[后端技术]</title>

<meta name="description" content="在Java中，通常通讯类型的服务器对GC(Garbage Collection)比较敏感。通常通讯服务器每秒需要处理大量进出的数据包，需要解析，分解成不同的业务逻辑对象并做相关的业务处理，这样会导致大量的临时对象被创建和回收。同时服务器如果需要同时保存用户状态的话，又会产生很多永久的对象，比如用户session。业务越复杂的应用往往用户session包含的引用对象就越多。这样在极端情况下会发生两件事情，long gc pause time 或 out of memory。
一，要解决long pause time首先要了解JVM中heap的结构

Java Heap为什么要分成几个不同的代(generation)? 由于80%-98%的对象的生存周期很短，大部分新对象存放在young generation可以很高效的回收，避免遍历所有对象。
young与old中内存分配的算法完全不同。young generation中由于存活的很少，要mark, sweep 然后再 compact 剩余的对象比较耗时，干脆把 live object copy 到另外一个空间更高效。old generation完全相反，里面的 live object 变化较少。因此采用 mark-sweep-compact更合适。

二，Java中四种垃圾回收算法
Java中有四种不同的回收算法，对应的启动参数为
–XX:+UseSerialGC
–XX:+UseParallelGC
–XX:+UseParallelOldGC
–XX:+UseConcMarkSweepGC
1. Serial Collector
大部分平台或者强制 java -client 默认会使用这种。
young generation算法 = serial
old generation算法 = serial (mark-sweep-compact)
这种方法的缺点很明显，stop-the-world, 速度慢。服务器应用不推荐使用。
2. Parallel Collector
在linux x64上默认是这种，其他平台要加 java -server 参数才会默认选用这种。
young = parallel，多个thread同时copy
old = mark-sweep-compact = 1
优点：新生代回收更快。因为系统大部分时间做的gc都是新生代的，这样提高了throughput(cpu用于非gc时间)
缺点：当运行在8G/16G server上old generation [...]">
<link rel="stylesheet" type="text/css" href="./Java垃圾回收调优 – Tim[后端技术]_files/style.css">
<!--[if IE 5]>
<style type="text/css"> 
/* IE 5 does not use the standard box model, so the column widths are overidden to render the page correctly. */
#outerWrapper #contentWrapper #rightColumn {
  width: 220px;
}
</style>
<![endif]-->
<!--[if IE]>
<style type="text/css"> 
/* The proprietary zoom property gives IE the hasLayout property which addresses several bugs. */
#outerWrapper #contentWrapper #content {
  zoom: 1;
}
</style>
<![endif]-->
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="http://timyang.net/feed/atom/">
<link rel="alternate" type="application/rss+xml" title="Tim[后端技术] RSS Feed" href="http://timyang.net/feed/">
<link rel="pingback" href="http://timyang.net/blog/xmlrpc.php">
<link rel="alternate" type="application/rss+xml" title="Tim[后端技术] » Java垃圾回收调优 Comments Feed" href="http://timyang.net/java/java_gc_tunning/feed/">
<link rel="stylesheet" id="wp-pagenavi-css" href="./Java垃圾回收调优 – Tim[后端技术]_files/pagenavi-css.css" type="text/css" media="">
<script type="text/javascript" src="./Java垃圾回收调优 – Tim[后端技术]_files/comment-reply.js"></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://timyang.net/blog/xmlrpc.php?rsd">
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://timyang.net/blog/wp-includes/wlwmanifest.xml"> 
<link rel="index" title="Tim[后端技术]" href="http://timyang.net/">
<link rel="start" title="陈杰谈网游服务器的后端技术" href="http://timyang.net/architecture/game-backend/">
<link rel="prev" title="参加Erlang开发者大会一些记录" href="http://timyang.net/erlang/cn-erlounge-iii/">
<link rel="next" title="使用Google App Engine写的农历日历" href="http://timyang.net/programming/google-app-engine-calendar/">
<meta name="generator" content="WordPress 2.9.1">
<link rel="canonical" href="./Java垃圾回收调优 – Tim[后端技术]_files/Java垃圾回收调优 – Tim[后端技术].htm">
	<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
</head>
<body>
<div id="outerWrapper">
<div id="header">
<h1><a title="Home" href="http://timyang.net/">Tim[后端技术]</a></h1>
<span class="description">Tim's blog, 关于后端架构、互联网技术、分布式、大型网络应用、NoSQL、技术感悟等</span>
</div>
<form method="get" id="searchform" action="http://timyang.net/"> 
<div class="navbar"><a href="http://timyang.net/">Home</a> | <a href="http://timyang.net/about/">About</a> | <a href="http://timyang.net/tag/English/">English version</a> | <a href="http://timyang.net/about/#comment">留言(Guestbook)</a> | <a href="http://timyang.net/feed/"><img src="./Java垃圾回收调优 – Tim[后端技术]_files/feed-icon.gif"></a><a href="http://timyang.net/feed/">订阅RSS</a> <a href="http://fusion.google.com/add?source=atgs&feedurl=http%3A//timyang.net/feed/"><img src="./Java垃圾回收调优 – Tim[后端技术]_files/plus_google.gif" border="0" alt="Add to Google"></a> 
<label class="hidden" for="s"></label> <input type="text" name="s" id="s" value=""> <input type="submit" id="searchsubmit" value="Search">
</div></form><div id="contentWrapper">
<div id="rightColumn">
<li>
<ul><li>			<div class="textwidget">Email: <img src="./Java垃圾回收调优 – Tim[后端技术]_files/email.png"></div>
		</li></ul><ul><li><h3>Similar Posts</h3><ul><li><a href="http://timyang.net/programming/thrift-protocol-buffers-performance-java/" rel="bookmark" title="April 2, 2009">Thrift and Protocol Buffers performance in Java</a></li>

<li><a href="http://timyang.net/programming/thrift-protocol-buffers-performance-2/" rel="bookmark" title="April 17, 2009">Thrift and Protocol Buffers performance in Java Round 2</a></li>

<li><a href="http://timyang.net/programming/thrift-protocol-buffers-java-howto/" rel="bookmark" title="April 2, 2009">Thrift, Protocol Buffers installation and Java code howto</a></li>

<li><a href="http://timyang.net/programming/c-erlang-java-performance/" rel="bookmark" title="November 11, 2009">C, Erlang, Java and Go Web Server performance test</a></li>

<li><a href="http://timyang.net/architecture/notes-timelines-twitter/" rel="bookmark" title="May 3, 2012">Notes about Timelines @ Twitter</a></li>
</ul><!-- Similar Posts took 12.341 ms --></li></ul><ul><li><h3>Most Commented</h3><ul><li><a href="http://timyang.net/data/mcdb-tt-redis/" title="MemcacheDB, Tokyo Tyrant, Redis performance test">MemcacheDB, Tokyo Tyrant, Redis performance test</a> (103)</li><li><a href="http://timyang.net/programming/c-erlang-java-performance/" title="C, Erlang, Java and Go Web Server performance test">C, Erlang, Java and Go Web Server performance test</a> (85)</li><li><a href="http://timyang.net/about/" title="About Tim Yang">About Tim Yang</a> (84)</li><li><a href="http://timyang.net/data/redis-misunderstanding/" title="Redis几个认识误区">Redis几个认识误区</a> (64)</li><li><a href="http://timyang.net/programming/memcache-mutex/" title="Memcache mutex设计模式">Memcache mutex设计模式</a> (47)</li><li><a href="http://timyang.net/architecture/microblog-design-qcon-beijing/" title="构建可扩展的微博架构(qcon beijing 2010演讲)">构建可扩展的微博架构(qcon beijing 2010演讲)</a> (40)</li><li><a href="http://timyang.net/architecture/consistent-hashing-practice/" title="某分布式应用实践一致性哈希的一些问题">某分布式应用实践一致性哈希的一些问题</a> (39)</li><li><a href="http://timyang.net/misc/macbook-air-productive/" title="MacBook Air与工作效率">MacBook Air与工作效率</a> (35)</li><li><a href="http://timyang.net/google/open-source/" title="为什么优秀开发者进入Google后就不参与开源了">为什么优秀开发者进入Google后就不参与开源了</a> (34)</li><li><a href="http://timyang.net/data/memcached-lru-evictions/" title="Memcached数据被踢(evictions&gt;0)现象分析">Memcached数据被踢(evictions&gt;0)现象分析</a> (30)</li></ul></li></ul>		<ul><li>		<h3>Recent Posts</h3>		<ul>
				<li><a href="http://timyang.net/tao/innovation/" title="谈分享、创新与开源">谈分享、创新与开源 </a></li>
				<li><a href="http://timyang.net/architecture/micro-vs-macro/" title="微观架构及宏观架构">微观架构及宏观架构 </a></li>
				<li><a href="http://timyang.net/tao/speech-practice/" title="演讲小组的第一次活动">演讲小组的第一次活动 </a></li>
				<li><a href="http://timyang.net/tao/connect-the-dots/" title="“connect the dots” 随想">“connect the dots” 随想 </a></li>
				<li><a href="http://timyang.net/tao/talents/" title="跨领域人才">跨领域人才 </a></li>
				<li><a href="http://timyang.net/product/discontinued-servic/" title="产品下线杂谈">产品下线杂谈 </a></li>
				<li><a href="http://timyang.net/misc/speech/" title="当我谈演讲时候，我谈些什么">当我谈演讲时候，我谈些什么 </a></li>
				<li><a href="http://timyang.net/architecture/k/" title="案例与故障的知识库">案例与故障的知识库 </a></li>
				<li><a href="http://timyang.net/management/learning-tao/" title="团队中的为师之道">团队中的为师之道 </a></li>
				<li><a href="http://timyang.net/google/hybrid-research/" title="有感Google的混合研究方法">有感Google的混合研究方法 </a></li>
				<li><a href="http://timyang.net/management/probation/" title="谈技术人员“转正”">谈技术人员“转正” </a></li>
				<li><a href="http://timyang.net/architecture/notes-weixin/" title="微信架构的启示">微信架构的启示 </a></li>
				<li><a href="http://timyang.net/misc/macbook-air-productive/" title="MacBook Air与工作效率">MacBook Air与工作效率 </a></li>
				<li><a href="http://timyang.net/architecture/notes-timelines-twitter/" title="Notes about Timelines @ Twitter">Notes about Timelines @ Twitter </a></li>
				<li><a href="http://timyang.net/management/engineer-performance/" title="技术工程师的能力与目标">技术工程师的能力与目标 </a></li>
				</ul>
		</li></ul>		<ul><li>			<h3>Recent Comments</h3>			<ul id="recentcomments"><li class="recentcomments"><a href="http://www.dbthink.com/" rel="external nofollow" class="url">jametong</a> on <a href="http://timyang.net/architecture/micro-vs-macro/comment-page-1/#comment-250202">微观架构及宏观架构</a></li><li class="recentcomments"><a href="http://www.zerolang.com/2013/01/%e5%a5%bd%e6%96%87%e7%ab%a0%e6%95%b4%e7%90%86/" rel="external nofollow" class="url">ZeroLang » 好文章整理</a> on <a href="http://timyang.net/tech/quality-or-death/comment-page-1/#comment-250174">有故障，毋宁死</a></li><li class="recentcomments">Everest on <a href="http://timyang.net/architecture/micro-vs-macro/comment-page-1/#comment-250139">微观架构及宏观架构</a></li><li class="recentcomments"><a href="http://blog.cydu.net/" rel="external nofollow" class="url">cydu</a> on <a href="http://timyang.net/architecture/micro-vs-macro/comment-page-1/#comment-249593">微观架构及宏观架构</a></li><li class="recentcomments"><a href="http://www.yanjiuyanjiu.com/" rel="external nofollow" class="url">soulmachine</a> on <a href="http://timyang.net/architecture/micro-vs-macro/comment-page-1/#comment-249536">微观架构及宏观架构</a></li></ul>
		</li></ul><ul><li><h3>Categories</h3>		<ul>
	<li class="cat-item cat-item-79"><a href="http://timyang.net/category/data/" title="View all posts filed under data">data</a>
</li>
	<li class="cat-item cat-item-3"><a href="http://timyang.net/category/erlang/" title="Erlang语言">Erlang</a>
</li>
	<li class="cat-item cat-item-52"><a href="http://timyang.net/category/google/" title="View all posts filed under Google">Google</a>
</li>
	<li class="cat-item cat-item-7"><a href="http://timyang.net/category/java/" title="View all posts filed under Java">Java</a>
</li>
	<li class="cat-item cat-item-32"><a href="http://timyang.net/category/linux/" title="View all posts filed under Linux">Linux</a>
</li>
	<li class="cat-item cat-item-28"><a href="http://timyang.net/category/lua/" title="View all posts filed under Lua">Lua</a>
</li>
	<li class="cat-item cat-item-10"><a href="http://timyang.net/category/python/" title="View all posts filed under Python">Python</a>
</li>
	<li class="cat-item cat-item-57"><a href="http://timyang.net/category/sns/" title="View all posts filed under SNS">SNS</a>
</li>
	<li class="cat-item cat-item-69"><a href="http://timyang.net/category/tech/" title="View all posts filed under tech">tech</a>
</li>
	<li class="cat-item cat-item-17"><a href="http://timyang.net/category/web/" title="View all posts filed under Web">Web</a>
</li>
	<li class="cat-item cat-item-58"><a href="http://timyang.net/category/product/" title="View all posts filed under 产品">产品</a>
</li>
	<li class="cat-item cat-item-87"><a href="http://timyang.net/category/distributed/" title="分布式算法及思想">分布式</a>
</li>
	<li class="cat-item cat-item-130"><a href="http://timyang.net/category/management/" title="View all posts filed under 技术管理">技术管理</a>
</li>
	<li class="cat-item cat-item-1"><a href="http://timyang.net/category/architecture/" title="后端架构">架构</a>
</li>
	<li class="cat-item cat-item-9"><a href="http://timyang.net/category/programming/" title="View all posts filed under 编程">编程</a>
</li>
	<li class="cat-item cat-item-134"><a href="http://timyang.net/category/tao/" title="View all posts filed under 随想">随想</a>
</li>
	<li class="cat-item cat-item-72"><a href="http://timyang.net/category/misc/" title="非技术话题">非技术</a>
</li>
		</ul>
</li></ul><ul><li><h3>Archives</h3>		<ul>
			<li><a href="http://timyang.net/2013/01/" title="January 2013">January 2013</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2012/10/" title="October 2012">October 2012</a>&nbsp;(5)</li>
	<li><a href="http://timyang.net/2012/09/" title="September 2012">September 2012</a>&nbsp;(4)</li>
	<li><a href="http://timyang.net/2012/05/" title="May 2012">May 2012</a>&nbsp;(3)</li>
	<li><a href="http://timyang.net/2012/02/" title="February 2012">February 2012</a>&nbsp;(3)</li>
	<li><a href="http://timyang.net/2012/01/" title="January 2012">January 2012</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2011/12/" title="December 2011">December 2011</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2011/08/" title="August 2011">August 2011</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2011/07/" title="July 2011">July 2011</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2011/04/" title="April 2011">April 2011</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2011/02/" title="February 2011">February 2011</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2011/01/" title="January 2011">January 2011</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2010/12/" title="December 2010">December 2010</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2010/11/" title="November 2010">November 2010</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2010/09/" title="September 2010">September 2010</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2010/08/" title="August 2010">August 2010</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2010/07/" title="July 2010">July 2010</a>&nbsp;(3)</li>
	<li><a href="http://timyang.net/2010/06/" title="June 2010">June 2010</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2010/05/" title="May 2010">May 2010</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2010/04/" title="April 2010">April 2010</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2010/03/" title="March 2010">March 2010</a>&nbsp;(4)</li>
	<li><a href="http://timyang.net/2010/02/" title="February 2010">February 2010</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2010/01/" title="January 2010">January 2010</a>&nbsp;(1)</li>
	<li><a href="http://timyang.net/2009/12/" title="December 2009">December 2009</a>&nbsp;(3)</li>
	<li><a href="http://timyang.net/2009/11/" title="November 2009">November 2009</a>&nbsp;(3)</li>
	<li><a href="http://timyang.net/2009/10/" title="October 2009">October 2009</a>&nbsp;(3)</li>
	<li><a href="http://timyang.net/2009/09/" title="September 2009">September 2009</a>&nbsp;(4)</li>
	<li><a href="http://timyang.net/2009/08/" title="August 2009">August 2009</a>&nbsp;(5)</li>
	<li><a href="http://timyang.net/2009/07/" title="July 2009">July 2009</a>&nbsp;(6)</li>
	<li><a href="http://timyang.net/2009/06/" title="June 2009">June 2009</a>&nbsp;(5)</li>
	<li><a href="http://timyang.net/2009/05/" title="May 2009">May 2009</a>&nbsp;(11)</li>
	<li><a href="http://timyang.net/2009/04/" title="April 2009">April 2009</a>&nbsp;(7)</li>
	<li><a href="http://timyang.net/2009/03/" title="March 2009">March 2009</a>&nbsp;(3)</li>
	<li><a href="http://timyang.net/2009/02/" title="February 2009">February 2009</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2009/01/" title="January 2009">January 2009</a>&nbsp;(2)</li>
	<li><a href="http://timyang.net/2008/12/" title="December 2008">December 2008</a>&nbsp;(2)</li>
		</ul>
</li></ul></li><li>
<h3>Feeds</h3>
<ul>
<li><a href="http://timyang.net/feed/">Entries (RSS)</a></li>
<li><a href="http://timyang.net/comments/feed/">Comments (RSS)</a></li>
</ul>
</li>
<li>
<form method="get" id="searchform" action="http://timyang.net/">
<div><label class="hidden" for="s"></label>
<input type="text" size="15" value="" name="s" id="s">
<input type="submit" id="searchsubmit" value="Search"></div>
</form></li>
</div><div id="content">
<div class="post-17 post hentry category-java tag-gc tag-java" id="post-17">
<h2 class="posttitle"><a href="./Java垃圾回收调优 – Tim[后端技术]_files/Java垃圾回收调优 – Tim[后端技术].htm" rel="bookmark" title="Permanent Link to Java垃圾回收调优">Java垃圾回收调优</a></h2>
<div class="postinfo">
Wednesday, Jan 7th, 2009  by Tim  | Tags: <a href="http://timyang.net/tag/gc/" rel="tag">GC</a>, <a href="http://timyang.net/tag/java/" rel="tag">Java</a><br></div>
<div class="entry">
<p>在Java中，通常通讯类型的服务器对GC(Garbage Collection)比较敏感。通常通讯服务器每秒需要处理大量进出的数据包，需要解析，分解成不同的业务逻辑对象并做相关的业务处理，这样会导致大量的临时对象被创建和回收。同时服务器如果需要同时保存用户状态的话，又会产生很多永久的对象，比如用户session。业务越复杂的应用往往用户session包含的引用对象就越多。这样在极端情况下会发生两件事情，long gc pause time 或 out of memory。</p>
<p>一，要解决long pause time首先要了解JVM中heap的结构</p>
<div id="attachment_18" class="wp-caption alignnone" style="width: 519px"><img class="size-full wp-image-18" title="java gc heap" src="./Java垃圾回收调优 – Tim[后端技术]_files/java-gc.png" alt="java gc heap" width="509" height="398"><p class="wp-caption-text">java gc heap</p></div>
<ul>
<li>Java Heap为什么要分成几个不同的代(generation)? 由于80%-98%的对象的生存周期很短，大部分新对象存放在young generation可以很高效的回收，避免遍历所有对象。</li>
<li>young与old中内存分配的算法完全不同。young generation中由于存活的很少，要mark, sweep 然后再 compact 剩余的对象比较耗时，干脆把 live object copy 到另外一个空间更高效。old generation完全相反，里面的 live object 变化较少。因此采用 mark-sweep-compact更合适。</li>
</ul>
<p>二，Java中四种垃圾回收算法</p>
<p>Java中有四种不同的回收算法，对应的启动参数为<br>
–XX:+UseSerialGC<br>
–XX:+UseParallelGC<br>
–XX:+UseParallelOldGC<br>
–XX:+UseConcMarkSweepGC</p>
<p>1. Serial Collector<br>
大部分平台或者强制 java -client 默认会使用这种。<br>
young generation算法 = serial<br>
old generation算法 = serial (mark-sweep-compact)<br>
这种方法的缺点很明显，stop-the-world, 速度慢。服务器应用不推荐使用。</p>
<p>2. Parallel Collector<br>
在linux x64上默认是这种，其他平台要加 java -server 参数才会默认选用这种。<br>
young = parallel，多个thread同时copy<br>
old = mark-sweep-compact = 1<br>
优点：新生代回收更快。因为系统大部分时间做的gc都是新生代的，这样提高了throughput(cpu用于非gc时间)<br>
缺点：当运行在8G/16G server上old generation live object太多时候pause time过长</p>
<p>3. Parallel Compact Collector (ParallelOld)<br>
young = parallel = 2<br>
old = parallel，分成多个独立的单元，如果单元中live object少则回收，多则跳过<br>
优点：old old generation上性能较 parallel 方式有提高<br>
缺点：大部分server系统old generation内存占用会达到60%-80%, 没有那么多理想的单元live object很少方便迅速回收，同时compact方面开销比起parallel并没明显减少。</p>
<p>4. Concurent Mark-Sweep(CMS) Collector<br>
young generation = parallel collector = 2<br>
old = cms<br>
同时不做 compact 操作。<br>
优点：pause time会降低, pause敏感但CPU有空闲的场景需要建议使用策略4.<br>
缺点：cpu占用过多，cpu密集型服务器不适合。另外碎片太多，每个object的存储都要通过链表连续跳n个地方，空间浪费问题也会增大。</p>
<p>几条经验：<br>
1. java -server<br>
2. 设置Xms=Xmx=3/4物理内存<br>
3. 如果是CPU密集型服务器，使用–XX:+UseParallelOldGC, 否则–XX:+UseConcMarkSweepGC<br>
4. 新生代,Parallel/ParallelOld可设大于Xmx1/4，CMS可设小，小于Xmx1/4<br>
5. 优化程序，特别是每个用户的session中的集合类等。我们的一个模块中session中曾经为每个用户使用了一个ConcurrentHashMap, 里面通常只有几条记录，后来改成数组之后，每台机大概节约了1~2G内存。</p>
<p>不过总的说来，Java的GC算法感觉是业界最成熟的，目前很多其他语言或者框架也都支持GC了，但大多数都是只达到Java Serial gc这种层面，甚至分generation都未考虑。JDK7里面针对CMS又进行了一种改进，会采用一种G1(Garbage-First Garbage Collection)的算法。实际上<a href="http://research.sun.com/jtech/pubs/04-g1-paper-ismm.pdf" target="_blank">Garbage-First paper</a>(PDF) 2004年已经出来了，相信到JDK7已经可以用于严格生产环境，有时间也会进一步介绍一下G1。<br>
另外在今年的Sun Tech Days上<a href="http://blogs.sun.com/joeys/" target="_blank">Joey Shen</a>讲的<a href="http://download.developers.sun.com.cn/event/sun_tech_day_china/2008/20081122_beijing_day2/track1/6_TD09_JavaPerformance_JoeyS.pdf" target="_blank">Improving Java Performance</a>(PDF)也是一个很好的Java GC调优的入门教程。</p>
</div>
</div>
<!-- You can start editing here. -->
<h4 id="comments">
7 Comments&nbsp;
<a href="http://timyang.net/java/java_gc_tunning/#postcomment" title="Jump to the comments form">»</a>
</h4>
<ol class="commentlist">
   <li class="comment even thread-even depth-1" id="li-comment-39">
     <div id="comment-39">
      <div class="comment-author vcard">
         <img alt="" src="./Java垃圾回收调优 – Tim[后端技术]_files/08ec8a1ca8c55f494a203be312e80e82" class="avatar avatar-32 photo" height="32" width="32">
         <cite class="fn">xZeus</cite> <span class="says">says:</span>      </div>
      
      <div class="comment-meta commentmetadata"><a href="http://timyang.net/java/java_gc_tunning/comment-page-1/#comment-39">Apr 15th 2009 at 10:40</a></div>

      <p>java的gc调优需要分jvm版本的，ibm的jvm和sun的jvm的gc策略和架构就不一样，调优的方式也不一样，比如ibm的jvm在调整jvm的回收策略的时候调p簇和k簇，sun的就没有。</p>

      <div class="reply">
               </div>
     </div>
</li>
   <li class="comment odd alt thread-odd thread-alt depth-1 microid-mailto+http:sha1:5f90ce59a617db307c8487a004a97b1e483aac57" id="li-comment-1483">
     <div id="comment-1483">
      <div class="comment-author vcard">
         <img alt="" src="./Java垃圾回收调优 – Tim[后端技术]_files/a41f30a39c39e8bba74e9b8c18e16c9e" class="avatar avatar-32 photo" height="32" width="32">
         <cite class="fn"><a href="http://blog.chenlb.com/" rel="external nofollow" class="url">chenlb</a></cite> <span class="says">says:</span>      </div>
      
      <div class="comment-meta commentmetadata"><a href="http://timyang.net/java/java_gc_tunning/comment-page-1/#comment-1483">Sep 4th 2009 at 11:09</a></div>

      <p>总结得好。</p>

      <div class="reply">
               </div>
     </div>
</li>
   <li class="comment even thread-even depth-1" id="li-comment-22347">
     <div id="comment-22347">
      <div class="comment-author vcard">
         <img alt="" src="./Java垃圾回收调优 – Tim[后端技术]_files/9cd878c93b6ceefdc6ef4bd3b2a6a061" class="avatar avatar-32 photo" height="32" width="32">
         <cite class="fn">楼拴柱</cite> <span class="says">says:</span>      </div>
      
      <div class="comment-meta commentmetadata"><a href="http://timyang.net/java/java_gc_tunning/comment-page-1/#comment-22347">Apr 13th 2011 at 14:50</a></div>

      <p>2. 设置Xms=Xmx=3/4物理内存</p>
<p>这一条不太理解，物理内存指的是机器的总内存？</p>
<p>我这台机器上要是想起多个虚拟机怎么办？且每个都需要一样的内存大小，怎么分配，不能一个就占物理内存的3/4吧</p>

      <div class="reply">
               </div>
     </div>
</li>
   <li class="comment odd alt thread-odd thread-alt depth-1" id="li-comment-22358">
     <div id="comment-22358">
      <div class="comment-author vcard">
         <img alt="" src="./Java垃圾回收调优 – Tim[后端技术]_files/9cd878c93b6ceefdc6ef4bd3b2a6a061" class="avatar avatar-32 photo" height="32" width="32">
         <cite class="fn">楼拴柱</cite> <span class="says">says:</span>      </div>
      
      <div class="comment-meta commentmetadata"><a href="http://timyang.net/java/java_gc_tunning/comment-page-1/#comment-22358">Apr 13th 2011 at 15:21</a></div>

      <p>5. 优化程序，特别是每个用户的session中的集合类等。我们的一个模块中session中曾经为每个用户使用了一个ConcurrentHashMap, 里面通常只有几条记录，后来改成数组之后，每台机大概节约了1~2G内存。</p>
<p>这个太诧异了，每个用户存一个ConcurrentHashMap，这么浪费内存的事情是怎么想出来的</p>

      <div class="reply">
               </div>
     </div>
</li>
</ol>
<p class="small">
<a href="http://timyang.net/java/java_gc_tunning/feed/"><abbr title="Really Simple Syndication">RSS</abbr> feed for comments on this post</a>, <a href="http://timyang.net/java/java_gc_tunning/trackback/" rel="trackback">TrackBack <abbr title="Uniform Resource Identifier">URI</abbr></a>
</p>
<div class="navigation">
<div class="alignleft"></div>
<div class="alignright"></div>
<br>
</div>
<div id="respond">
<div class="cancel-comment-reply">
<a rel="nofollow" id="cancel-comment-reply-link" href="http://timyang.net/java/java_gc_tunning/#respond" style="display:none;">Cancel Reply</a></div>
<h4 id="postcomment">Leave a Comment</h4>
<form action="http://timyang.net/blog/wp-comments-post.php" method="post" id="commentform">
<p>
<input type="text" name="author" id="author" value="" size="20" tabindex="1">
<label for="author">Name (required)</label>
</p>
<p>
<input type="text" name="email" id="email" value="" size="20" tabindex="2">
<label for="email">E-mail (required, never displayed)</label>
</p>
<p>
<input type="text" name="url" id="url" value="" size="20" tabindex="3">
<label for="url"><abbr title="Uniform Resource Identifier">URI</abbr></label>
</p>
<p>
<textarea name="comment" id="comment" cols="80" rows="10" tabindex="4"></textarea>
</p>
<p>
<input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment">
<input type="hidden" name="comment_post_ID" value="17">
<input type="hidden" name="comment_post_ID" value="17" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</p>
</form>
</div>
	
</div>
<br class="clearFloat">
</div>
<div id="footer">
<p><small>Except where otherwise noted, content on this site is licensed under a <a href="http://creativecommons.org/licenses/by/3.0/" target="_blank">Creative Commons Attribution 3.0</a> License</small></p>
</div>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><script src="./Java垃圾回收调优 – Tim[后端技术]_files/ga.js" type="text/javascript"></script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-8036291-3");
pageTracker._trackPageview();
} catch(err) {}</script>

</body></html>